<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <!--{include file='comm/comm_cal.tpl'}-->
    <title><!--{if isset($customer_array)}-->修改会员<!--{else}-->新增会员<!--{/if}--></title>
    <!--{include file='comm/comm_region.tpl'}-->
    <!--{include file="comm/icheck.tpl"}-->
    <!--{include file='comm/comm_editor.tpl'}-->
</head>
<body>
<div style="width:100%" class="">


    <div class="panel panel-default" style="margin: 5px;">

        <div class="panel-heading"><!--{if isset($customer_array)}-->修改会员<!--{else}-->新增会员<!--{/if}--></div>

        <div class="panel-body">

            <form id="edit_form" class="form-horizontal" onsubmit="return false;">

                <!--{if isset($customer_array)}-->

                    <div class="form-group">
                        <label class="col-sm-2 control-label"> 会员名：</label>
                        <div class="col-sm-10">
                            <p class="form-control-static"><!--{$customer_array.custID}--></p>
                            <input type="hidden"  id="pcustID" name="pcustID" value="<!--{$customer_array.pcustID}-->" />
                        </div>
                    </div>

                <!--{else}-->

                    <div class="form-group">
                        <label for="" class="col-sm-2 control-label"></label>
                        <div class="col-sm-10">
                            <font color="red">注册成功后系统会将用户登录密码发送到用户注册手机上</font>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="custID"> 会员名：</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control w300" id="custID" name="custID" >
                            <input  type="hidden"  id="pcustID" name="pcustID" value="0" />
                        </div>
                    </div>

                <!--{/if}-->

                <div class="form-group">
                    <label class="col-sm-2 control-label"> 头像：</label>
                    <div class="col-sm-10">
                        <button type="button" class="btn btn-default" id="update_head_pic" >点击上传头像</button>
                        <div id="head_pic_box" style="margin-top: 5px;">
                            <!--{if isset($customer_array) && $customer_array.head_pic_link}-->
                            <img src="<!--{$customer_array.head_pic_link}-->">
                            <a id="del_head_pic" href="javascript: void(0);">删除</a>
                            <!--{/if}-->
                        </div>
                    </div>
                    <input type="hidden" name="head_pic" id="head_pic" value="<!--{$customer_array.head_pic_link|default:''}-->" />
                </div>

                <div class="form-group">
                    <label for="nickName" class="col-sm-2 control-label"><span class="red">*</span> 会员昵称：</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control w300" id="nickName" name="nickName" value="<!--{$customer_array.nickName|default:''}-->" placeholder="请输入会员昵称">
                    </div>
                </div>

                <div class="form-group">
                    <label for="custname" class="col-sm-2 control-label"><span class="red">*</span> 会员姓名：</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control w300" id="custname" name="custname" value="<!--{$customer_array.custname|default:''}-->" placeholder="请输入会员姓名">
                    </div>
                </div>

                <div class="form-group">
                    <label for="phone" class="col-sm-2 control-label"> 固定电话：</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control w300" id="phone" name="phone" value="<!--{$customer_array.phone|default:''}-->" placeholder="请输入固定电话">
                    </div>
                </div>

                <div class="form-group">
                    <label for="mobile" class="col-sm-2 control-label"><span class="red">*</span> 手机号码：</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control w300" id="mobile" name="mobile" value="<!--{$customer_array.mobile|default:''}-->" placeholder="请输入手机号码">
                    </div>
                </div>

                <div class="form-group">
                    <label for="email" class="col-sm-2 control-label"> 邮箱：</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control w300" id="email" name="email" value="<!--{$customer_array.email|default:''}-->" placeholder="请输入邮箱">
                    </div>
                </div>

                <div class="form-group">
                    <label  class="col-sm-2 control-label"><span class="red">*</span> 性别：</label>
                    <div class="col-sm-10">
                        <div class="fl" style="margin-right: 10px;">
                            <input type="radio" class="square-radio" id="sexy-radio-1" name="sexy" value="1">
                            <label for="sexy-radio-1">男</label>
                        </div>
                        <div class="fl" style="margin-right: 10px;">
                            <input type="radio" class="square-radio" id="sexy-radio-2" name="sexy" value="2">
                            <label for="sexy-radio-2">女</label>
                        </div>
                        <div class="fl">
                            <input type="radio" class="square-radio" id="sexy-radio-3" name="sexy" value="3" checked>
                            <label for="sexy-radio-3">保密</label>
                        </div>
                    </div>
                </div>

                <div class="form-group">
                    <label for="birthday" class="col-sm-2 control-label"> 生日：</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control w150" id="birthday" name="birthday" value="<!--{$customer_array.birthday|default:''}-->" readonly="readonly" placeholder="点击选择生日">
                    </div>
                </div>

                <div class="form-group">
                    <label  class="col-sm-2 control-label"><span class="red">*</span> 会员来源：</label>
                    <div class="col-sm-10">
                        <div class="fl" style="margin-right: 10px;">
                            <input type="radio" class="square-radio" id="custSource-radio-1" name="custSource" value="1">
                            <label for="custSource-radio-1">PC</label>
                        </div>
                        <div class="fl" style="margin-right: 10px;">
                            <input type="radio" class="square-radio" id="custSource-radio-2" name="custSource" value="2">
                            <label for="custSource-radio-2">WAP</label>
                        </div>
                        <div class="fl" style="margin-right: 10px;">
                            <input type="radio" class="square-radio" id="custSource-radio-3" name="custSource" value="3">
                            <label for="custSource-radio-0">APP</label>
                        </div>
                        <div class="fl" style="margin-right: 10px;">
                            <input type="radio" class="square-radio" id="custSource-radio-4" name="custSource" value="4">
                            <label for="custSource-radio-4">微信</label>
                        </div>
                        <div class="fl" style="margin-right: 10px;">
                            <input type="radio" class="square-radio" id="custSource-radio-5" name="custSource" value="5" checked>
                            <label for="custSource-radio-5">客服</label>
                        </div>
                        <div class="fl" style="margin-right: 10px;">
                            <input type="radio" class="square-radio" id="custSource-radio-6" name="custSource" value="6">
                            <label for="custSource-radio-6">第三方</label>
                        </div>
                        <div class="fl" style="margin-right: 10px;">
                            <input type="radio" class="square-radio" id="custSource-radio-7" name="custSource" value="7">
                            <label for="custSource-radio-7">线下</label>
                        </div>
                    </div>
                </div>

                <div class="form-group">
                    <label  class="col-sm-2 control-label"><span class="red">*</span> 用户类型：</label>
                    <div class="col-sm-10">
                        <div class="fl" style="margin-right: 10px;">
                            <input type="radio" class="square-radio" id="custType-radio-1" name="custType" value="1" checked>
                            <label for="custType-radio-1">普通会员</label>
                        </div>
                        <div class="fl" style="margin-right: 10px;">
                            <input type="radio" class="square-radio" id="custType-radio-2" name="custType" value="2">
                            <label for="custType-radio-2">访客会员</label>
                        </div>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 control-label"> 省市区：</label>
                    <div class="col-sm-10">
                        <select class="form-control fl w150" id="province_list" name="provinceid" style="margin-right: 5px;">
                            <option value="">请选择...</option>
                        </select>
                        <select class="form-control fl w150" id="city_list" name="cityid" style="margin-right: 5px;">
                            <option value="">请选择...</option>
                        </select>
                        <select class="form-control fl w150" id="county_list" name="countyid">
                            <option value="">请选择...</option>
                        </select>
                    </div>
                </div>

                <div class="form-group">
                    <label for="address" class="col-sm-2 control-label"> 详细地址：</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control w500" id="address" name="address" value="<!--{$customer_array.address|default:''}-->" placeholder="请输入详细地址">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 control-label"> 月收入：</label>
                    <div class="col-sm-10">
                        <select class="form-control w150 fl" name="monthlyIncome" id="monthlyIncome" >
                            <option value="0">无收入</option>
                            <option value="1">2000元以下</option>
                            <option value="2">2000-3999元</option>
                            <option value="3">4000-5999元</option>
                            <option value="4">6000-7999元</option>
                            <option value="5">8000元以上</option>
                        </select>
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <button type="button" class="btn btn-primary" onclick="save();">保存</button>&nbsp;&nbsp;&nbsp;
                        <input type="button" class="btn btn-warning" onclick="E.closeWindows();" value="关闭" />
                    </div>
                </div>

            </form>

        </div>

    </div>


</div>

<script type="text/javascript">

    var cust_verification = 1;

    $(window).ready(function() {

        $('.square-radio').iCheck({
            checkboxClass: 'icheckbox_square-blue',
            radioClass: 'iradio_square-blue',
            increaseArea: '20%' // optional
        });


        <!--{if isset($customer_array)}-->

        //显示省市区
        E.region.init({
            p: 'province_list',
            c: 'city_list',
            a: 'county_list',
            pid: '<!--{$customer_array.provinceid}-->',
            cid: '<!--{$customer_array.cityid}-->',
            ccid: '<!--{$customer_array.countyid}-->'
        });

        $('#custSource-radio-<!--{$customer_array.custSource}-->').iCheck('check');
        $('#custType-radio-<!--{$customer_array.custSource}-->').iCheck('check');
        $('#monthlyIncome').val(<!--{$customer_array.monthlyIncome}-->);

        <!--{else}-->

        cust_verification = 0;

        $('#custID').blur(function() {

            var custID = E.trim($(this).val());

            if (E.isEmpty(custID) || !E.isMobile(custID)) {
                E.alert('会员名必须是手机号码', 1, function() {
                    $('#custID').focus().val('');
                });
            } else {
                E.loadding.open('正在检查会员号，请稍候...');
                E.ajax_get({
                    url: '/invokingAjax-backend/customer/customer.ajax?operFlg=4',
                    data: {
                        custID: custID
                    },
                    call: function( o ) {
                        E.loadding.close();
                        if (o.code == 200) {
                            E.alert('会员名已存在', 1, function() {
                                $('#custID').focus().val('');
                            });
                        } else {
                            $('#mobile').val(custID);
                            $('#nickName').val(custID);
                        }
                    }
                });
            }



        });

        //显示省市区
        E.region.init({
            p: 'province_list',
            c: 'city_list',
            a: 'county_list'
        });

        <!--{/if}-->

        <!--{if $mobile}-->
            $('#custID').val('<!--{$mobile}-->');
            $('#custID').blur();
        <!--{/if}-->

    });

    KindEditor.ready(function(K) {

        var kindEditor_upload = K.editor({
            allowFileManager : true,
            uploadJson: '/framework/kindeditor/php/upload_json.php?act=customer'
        });

        $(document).on('click', '#update_head_pic', function() {

            kindEditor_upload.loadPlugin('image', function() {
                kindEditor_upload.plugin.imageDialog({
                    showRemote : false,
                    clickFn : function(url) {

                        $('#head_pic_box').html('<img src="' + url + '"> <a href="javascript: void(0);" id="del_head_pic">删除</a>').show();
                        $('#head_pic').val(url);
                        kindEditor_upload.hideDialog();

                    }
                });
            });

        });

        $(document).on('click', '#del_head_pic', function() {
            $('#head_pic_box').html('').hide();
            $('#head_pic').val('');
        });

    });

    $('#birthday').datepicker();

    function save() {

        var dt = E.getFormValues("edit_form");
        var error_msg = "";

        if (dt.pcustID == 0) {
            if (E.isEmpty(dt.custID)) {
                error_msg += '请输入会员名<br>';
            } else if (!E.isMobile(dt.custID)) {
                error_msg += '会员名必须是手机号码<br>';
            }
        }

        if (E.isEmpty(dt.nickName)) {
            error_msg += "请输入会员昵称<br>";
        }

        if (E.isEmpty(dt.custname)) {
            error_msg += "请输入会员姓名<br>";
        }

        if (!E.isEmpty(dt.phone) && !E.isPhone(dt.phone)) {
            error_msg += "固定电话格式错误<br>";
        }

        if (E.isEmpty(dt.mobile)) {
            error_msg += "请输入手机号码<br>";
        }  else if (!E.isMobile(dt.mobile)) {
            error_msg += '手机号码格式错误<br>';
        }

        if (!E.isEmpty(dt.email) && !E.isEmail(dt.email)) {
            error_msg += "邮箱格式错误<br>";
        }

        if (!E.isEmpty(dt.birthday) && !E.isDate(dt.birthday)) {
            error_msg += "生日格式错误<br>";
        }

        if (error_msg != "") {
            E.alert(error_msg);
        } else {
            E.confirm('您确认要保存会员信息吗？', function() {

                E.loadding.open('正在保存，请稍候...');

                E.ajax_post({
                    url: '/invokingAjax-backend/customer/customer.ajax?operFlg=100&act=edit',
                    data: dt,
                    call: function( o ) {
                        E.loadding.close();
                        if (o.code == 200) {
                            E.opener('customer.load');
                            E.alert(o.message , 2 , 'E.closeWindows()');
                        } else {
                            E.alert(o.message);
                        }
                    }
                });

            });
        }

    }

</script>

</body>

</html>
